#ifndef __DHT11_H
#define __DHT11_H

#include <stdint.h>
#include "bflb_gpio.h"


typedef enum {
    DHT_CODE_SUCCEED = 0,
    DHT_CODE_NOACK,
    DHT_CODE_DATA_ERR,
}DHT_CODE;

typedef enum {
    DHT_STATUS_INIT = 0,
    DHT_STATUS_READY,
    DHT_STATUS_READING,

}DHT_STATUS;

typedef struct DHT11 {
    uint8_t pin;
    DHT_STATUS status;
}DHT11_t;

#ifdef cplusplus

extern "C" {
#endif

    /**
     * @brief dht初始化
     * @param  gpio
     * @param  dev
     * @param  pin 设备连接到的pin
     */
    void dht_init(struct bflb_device_s* gpio, DHT11_t* dev, uint8_t pin);
    /**
     * @brief 读取温湿度数据
     * @param  gpio
     * @param  dev
     * @param  temp   温度*10
     * @param  humidity  湿度*10
     * @return DHT_CODE 状态码
     */
    DHT_CODE dht_read_data(struct bflb_device_s* gpio, DHT11_t* dev, int16_t* temp, uint16_t* humidity);

#ifdef cplusplus
}
#endif
#endif